package avicit.im.lantop.basic.lexiconManager.service.api;


import avicit.im.lantop.basic.themewordmanager.domain.LantopThemeWord;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.restclient.RestClient;
import avicit.platform6.core.restclient.RestClientUtils;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class LantopLexiconServiceApi {


    /**
     * 服务编码
     */
    private static final String SERVICE_CODE = "filebasicmanager";

    private static final String BASE_PATH = "/api/avicit/im/lantop/basic/lexiconManager/rest/LantopLexiconServiceRest";

    @Autowired
    private RestClient restClient;


    /**
     * 查询是否有重复的关键词
     * @param orgId
     * @param formalThemeWord
     * @param id
     * @return
     */
    public int getCount(String orgId, String formalThemeWord, String id) {
        String url = BASE_PATH + "/getCount";
        Map<String,Object> map = new HashMap<>();
        map.put("orgId",orgId);
        map.put("formalThemeWord",formalThemeWord);
        map.put("id",id);
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    /**
     * 修改数据
     * @param themeWord
     */
    public void updateData(LantopThemeWord themeWord) {
        String url = BASE_PATH + "/updateData";
        Map<String,Object> map = new HashMap<>();
        map.put("themeWord",themeWord);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg>() {
        });
    }


    /**
     * 保存数据
     * @param themeWord
     */
    public void insertData(LantopThemeWord themeWord) {
        String url = BASE_PATH + "/insertData";
        Map<String,Object> map = new HashMap<>();
        map.put("themeWord",themeWord);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg>() {
        });
    }


    /**
     * 删除数据
     * @param ids
     */
    public void deleteThemeWord(String ids) {
        String url = BASE_PATH + "/deleteThemeWord";
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids);
        ResponseMsg responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg>() {
        });
    }


    /**
     * 获取数据
     * @param page
     * @param parameter
     * @return
     */
    public Page<LantopThemeWord> getPageList(Page<LantopThemeWord> page, Map<String, Object> parameter) {
        String url = BASE_PATH + "/getPageList";
        Map<String,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("parameter",parameter);
        ResponseMsg<Page<LantopThemeWord>> responseMsg = restClient.doPost(SERVICE_CODE, url, map, new ParameterizedTypeReference<ResponseMsg<Page<LantopThemeWord>>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
